package cn.iocoder.yudao.module.ride.service.bank;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ride.controller.admin.bank.vo.*;
import cn.iocoder.yudao.module.ride.dal.dataobject.bank.BankDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ride.dal.mysql.bank.BankMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.ride.enums.ErrorCodeConstants.*;

/**
 * 司机银行卡 Service 实现类
 *
 * @author 小胡同学
 */
@Service
@Validated
public class BankServiceImpl implements BankService {

    @Resource
    private BankMapper bankMapper;

    @Override
    public Long createBank(BankSaveReqVO createReqVO) {
        // 插入
        BankDO bank = BeanUtils.toBean(createReqVO, BankDO.class);
        bankMapper.insert(bank);

        // 返回
        return bank.getId();
    }

    @Override
    public void updateBank(BankSaveReqVO updateReqVO) {
        // 校验存在
        validateBankExists(updateReqVO.getId());
        // 更新
        BankDO updateObj = BeanUtils.toBean(updateReqVO, BankDO.class);
        bankMapper.updateById(updateObj);
    }

    @Override
    public void deleteBank(Long id) {
        // 校验存在
        validateBankExists(id);
        // 删除
        bankMapper.deleteById(id);
    }

    @Override
        public void deleteBankListByIds(List<Long> ids) {
        // 删除
        bankMapper.deleteByIds(ids);
        }


    private void validateBankExists(Long id) {
        if (bankMapper.selectById(id) == null) {
            throw exception(BANK_NOT_EXISTS);
        }
    }

    @Override
    public BankDO getBank(Long id) {
        return bankMapper.selectById(id);
    }

    @Override
    public PageResult<BankDO> getBankPage(BankPageReqVO pageReqVO) {
        return bankMapper.selectPage(pageReqVO);
    }

}